﻿using Abp.AutoMapper;
using AutoMapper;
using NetCore.Entities.Organizations;
using NetCore.Organizations.Dtos;
using NetCore.Users.Dto;

namespace NetCore.Organizations
{
    public class OrganizationDtoMapper : Profile
    {
        public OrganizationDtoMapper()
        {
            //这个地方必须使用三目运算符判断：因为FromUser ToUser Project 都有可能为null  可以不用判断
            CreateMap<Organization, OrganizationDto>()
                .ForMember(m => m.ParentName, opt => opt.MapFrom(n => n.Parent != null ? n.Parent.Name : string.Empty));
            CreateMap<OrganizationUser, OrganizationUserDto>()
                .ForMember(m => m.User, opt => opt.MapFrom(n => n.User.MapTo<UserDto>()))
                .ForMember(m => m.OrganizationName,
                    opt => opt.MapFrom(n => n.Organization != null ? n.Organization.Name : string.Empty));
        }
    }
}
